package com.qumitech.visualnovel.component.util;

/**
 * @Auther: bke
 * @Date: 2018/8/3 09:02
 * @Description: 排列组合计算工具类
 */
public class FactorialUtil {
    /**
     * @auther: bke 2018/8/3 8:57
     * description: 计算阶乘数，即n! = n * (n-1) * ... * 2 * 1
     */
    public static long factorial(int n) {
        return (n > 1) ? n * factorial(n - 1) : 1;
    }

    /**
     * @auther: bke 2018/8/3 8:59
     * description: 计算组合数，即C(n, m) = n!/((n-m)! * m!)
     */
    public static long combination(int n, int m) {
        return (n >= m) ? factorial(n) / factorial(n - m) / factorial(m) : 0;
    }

    /**
     * @auther: bke 2018/8/3 9:03
     * description: 计算排列数，即A(n, m) = n!/(n-m)!
     */
    public static long arrangement(int n, int m) {
        
        return (n >= m) ? factorial(n) / factorial(n - m) : 0;
    }
}
